package com.android.bonn.fast.net.converter;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * User: HuangYunLin(283857754@qq.com)
 * Date: 2016-08-19
 * Time: 17:50
 * FIXME
 */
public class JsonObjectResponseConverter<T extends String> implements Converter<ResponseBody, JSONObject> {

    JsonObjectResponseConverter() {
    }

    @Override
    public JSONObject convert(ResponseBody value) throws IOException {

        try {
            try {
                return new JSONObject(value.string());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } finally {
            value.close();
        }

        return new JSONObject();
    }
}